#include <stdio.h>
#include "hdmirx.h"
#include "typedef.h"

void my_init_hdmirx(void)
{
	hdmirx_clear_hpd();

    HDMIRX_WriteI2C_Byte(REG_RX_PWD_CTRL0, 0);
    HDMIRX_WriteI2C_Byte(0x07, 0x0c);
    HDMIRX_WriteI2C_Byte(0x05, 0x81);
    HDMIRX_WriteI2C_Byte(0x16, 0x0f);
    HDMIRX_WriteI2C_Byte(0x17, 0x07);
    HDMIRX_WriteI2C_Byte(0x18, 0x07);
    HDMIRX_WriteI2C_Byte(0x8c, 0x20);

    SetDefaultRegisterValue();

    RDROM_Reset(); // it should be do SWRESET again AFTER RDROM_Reset().
#ifdef SUPPORT_REPEATER
	RxHDCPRepeaterCapabilityClear(B_ENABLE_FEATURE_1P1|B_ENABLE_FAST);
    if(bHDCPMode & HDCP_REPEATER)
    {
	    RxHDCPRepeaterCapabilitySet(B_ENABLE_REPEATER);
	    RxHDCPRepeaterCapabilityClear(B_KSV_READY);
	}
	else
	{
	    RxHDCPRepeaterCapabilityClear(B_KSV_READY|B_ENABLE_REPEATER);
        SetIntMask3(~(B_R_AUTH_DONE|B_R_AUTH_START),B_ECCERR);
	}
#else
	HDMIRX_WriteI2C_Byte(REG_RX_CDEPTH_CTRL,HDMIRX_ReadI2C_Byte(REG_RX_CDEPTH_CTRL)&0xF);
#endif // SUPPORT_REPEATER

	delay1ms(500);

    HDMIRX_WriteI2C_Byte(0x07, 0x0);
    hdmirx_set_hpd();
}

void my_set_initial_value(void)
{
    HDMIRX_WriteI2C_Byte(0x08, 0xae);
    HDMIRX_WriteI2C_Byte(0x1d, 0x20);
    HDMIRX_WriteI2C_Byte(0x20, 0x20);
    HDMIRX_WriteI2C_Byte(0x3b, 0x40);
    HDMIRX_WriteI2C_Byte(0x68, 0x03);
    HDMIRX_WriteI2C_Byte(0x6b, 0x11);
    HDMIRX_WriteI2C_Byte(0x6c, 0x00);
    HDMIRX_WriteI2C_Byte(0x93, 0x43);
    HDMIRX_WriteI2C_Byte(0x94, 0x4f);
    HDMIRX_WriteI2C_Byte(0x95, 0x87);
    HDMIRX_WriteI2C_Byte(0x96, 0x33);
}

void my_set_hdmi_video_output(void)
{
    HDMIRX_WriteI2C_Byte(0x1b, 0x31); // Reg1B
    HDMIRX_WriteI2C_Byte(0x1c, 0x54); // Reg1C
    HDMIRX_WriteI2C_Byte(0x3d, 0x40); // Reg3D
}



